package handel

import (
	"context"
	"user_srv/global"
	"user_srv/types"
	pb "user_srv/users"
)

type UserSrvHandel struct {
	pb.UnimplementedUsersServer
}

func NewUserSrvHandel() *UserSrvHandel {
	return &UserSrvHandel{}
}

func (l *UserSrvHandel) UserAdd(ctx context.Context, req *pb.UserAddReq) (*pb.UserAddResp, error) {

	users := types.Users{
		Username: req.Username,
		Password: req.Password,
		Email:    req.Email,
		Phone:    req.Phone,
		Age:      int(req.Age),
		Address:  req.Address,
	}

	global.Db.Table("users").Create(&users)

	return &pb.UserAddResp{
		Code: 0,
		Msg:  "用户数据新增",
	}, nil
}
